Application Engine Peoplecode bind variables - peoplesoft

I have the below PeopleCode step in an Application Engine program that reads a CSV file using a File Layout and then inserts the data into a table, and I am just trying to get a better understanding of how the the line of code (&SQL1 = CreateSQL("%Insert(:1)");) in the below script gets generated. It looks like the CreateSQL is using a bind variable (:1) inside the Insert statement, but I am struggling as where to find where this variable is defined in the program.
Function EditRecord(&REC As Record) Returns boolean;
Local integer &E;
&REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_OneZero);
If &REC.IsEditError Then
For &E = 1 To &REC.FieldCount
&MYFIELD = &REC.GetField(&E);
If &MYFIELD.EditError Then
&MSGNUM = &MYFIELD.MessageNumber;
&MSGSET = &MYFIELD.MessageSetNumber;
&LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD.Name);
&LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, ""));
End-If;
End-For;
Return False;
Else
Return True;
End-If;
End-Function;
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
rem &SQL1 = CreateSQL("%Insert(:1) Order by COUNT_ORDER");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(#(&RecordName));
&RECP = &RSParent(1).GetRecord(#(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1, &FILE3;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
&FILE1 = GetFile("\\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.csv", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("\\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.txt", "r", "a", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&LOGFILE.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.GH_ITM_PR_UPDT);
REM &SQL1 = CreateSQL("%Insert(:1)");
&SQL1 = CreateSQL("%Insert(:1)");
/*Skip Header Row: The following line of code reads the first line in the file layout (the header)
and does nothing. Then the pointer goes to the next line in the file and starts using the
file.readrowset*/
&some_boolean = &FILE1.ReadLine(&string);
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;
&FILE1.Close();
&LOGFILE.Close();

The :1 is coming from the line further down &SQL1.Execute(&REC2);
&REC2 gets assigned a record object, so the line &SQL1.Execute(&REC2); evaluates to %Insert(your_record_object)
Here is a simple example that's doing basically the same thing
Here is a description of %Insert

Answer because too long to comment:
The table name is most likely (PS_)GH_ITM_PR_UPDT. The general consensus is to name the FileLayout the same as the record it is based on.
If not, it is defined in FileLayout.GH_ITM_PR_UPDT. Open the FileLayout, right click the segment and under 'Selected Node Properties' you will find the 'File Record Name'.
In your code this record is carried over into &RS1.
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
The rowset is a collection of rows. A row consists of records and a record is a row of data from a database table. (Peoplesoft Object Data Types are fun...)
This rowset is filled with data in the following statement:
&RS1 = &FILE1.ReadRowset();
This uses your file as input and outputs a rowset collection, mapping the data to records based on how you defined your FileLayout.
The result is fed into the ImportSegment function:
ImportSegment(&RS1, &RS);
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
&RS2 in the function is a reference to &RS1 in the rest of your code.
The table name is also hidden here:
&RecordName = "RECORD." | &RS2.DBRecordName;
So if you can't/don't want to check the FileLayout, you could output &RS2.DBRecordName with a messagebox and your answer will be Message Log of your Process Monitor.
Finally a record object is created for this database table and it is filled with a row from the rowset. This record is inserted into the database table:
&REC2 = CreateRecord(#(&RecordName));
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
&SQL1 = CreateSQL("%Insert(:1)");
&SQL1.Execute(&REC2);
TLDR:
Table name can be found in the FileLayout or output in the ImportSegment Function as &RS2.DBRecordName

Related

How to use unittest module for a python script which calls mutiple functions and uses global variables

This is one of the function in my python script for which I am trying to write unit test case, since it uses global variables and audit and big query functions which is written as different utility scripts I am not understanding how to write #patch and execute unit test cases for the same.
How will I patch global variables?
How to patch functions which doesn't have any return for eg :audit_event_source_table, can we ignore such functions during unit testing ? if so how to do the same?
How to do assertion as I do not have any return value but have logger.info messages?
import logging
from datetime import datetime
from pathlib import Path
import sys
import __main__
from intient_research_rdm_common.utils.audit_utils import audit_event_source_table, audit_event_job_table, \
get_job_id, get_source_object_id
from intient_research_rdm_kg_core.common_utils.utils.bigquery_utils import bigquery_data_read
from intient_research_rdm_kg_core.common_utils.utils.conf_read import read_args, read_source_config, read_env_config
global project_id, service_account, conn_ip, debug, node_table_list, edge_table_list, source_name
def edge_validation():
global edge_table_list
global source_name
edge_table_na = []
edge_table_list_rowcount_zero = []
dataset_e = "prep_e_" + source_name
row_count = 0
edge_table = ""
source_object_start_timestamp = datetime.now()
source_object_id = get_source_object_id(source_name, source_object_start_timestamp)
source_object_type = AUDIT_SOURCE_OBJECT_TYPE_BIGQUERY
job_id = get_job_id(source_object_start_timestamp)
source_object_name = dataset_e
try:
for edge_table in edge_table_list:
sql_query = " SELECT * FROM " + "`" + project_id + "." + dataset_e + ".__TABLES__` WHERE table_id =" + "'" + edge_table + "'"
data_read, col_names = bigquery_data_read(service_account, sql_query, project_id)
for ind in data_read.index:
row_count = (data_read['row_count'][ind])
if len(data_read.index) == 0:
edge_table_na.append(edge_table)
elif row_count == 0:
edge_table_list_rowcount_zero.append(edge_table)
if len(edge_table_na) > 0:
logging.info("Missing Edge tables in preprocessing layer {} ".format(edge_table_na))
if len(edge_table_list_rowcount_zero) > 0:
logging.info("Edge tables with row count as zero in Pre-processing layer {} ".format(edge_table_list_rowcount_zero))
if len(edge_table_na) == 0 and len(edge_table_list_rowcount_zero) == 0:
logging.info(
"Edge list validation for the source {} has been successfully completed with no discrepancies".format(
source_name))
audit_event_source_table(source_object_id, source_object_name, source_object_type, source_name,
source_object_name,
job_id, AUDIT_JOB_STATUS_PASS, source_object_start_timestamp,
datetime.now(), 'NA', 'NA', project_id)
if len(edge_table_na) > 0 or len(edge_table_list_rowcount_zero) > 0:
audit_event_source_table(source_object_id, source_object_name, source_object_type, source_name,
source_object_name,
job_id, AUDIT_JOB_STATUS_PASS, source_object_start_timestamp,
datetime.now(), 'NA', 'NA', project_id)
sys.exit(1)
except Exception as e:
msg = '{} : Issue with the edge validation for {} is: \n{}\n'.format(datetime.now(), edge_table, e)
logging.error(msg)
audit_event_source_table(source_object_id, source_object_name, source_object_type, source_name,
source_object_name,
job_id, AUDIT_JOB_STATUS_FAIL, source_object_start_timestamp,
datetime.now(), AUDIT_ERROR_TYPE_PREPROCESSING_KG_LAYER_VALIDATION, msg,
project_id)
raise Exception(msg)
Patch global variables - in the same way that you patch a method of a class, you patch the global variable. It's not clear in your code snippet where the global variables are defined (ie. do you import these variables from another module or do you assign to those variables at the top of your Python script). Either way, you patch in the namespace where the function is being used. If you can confirm further details I will be able to assist.
Personally, the way I patch and test functions with no return value is the same. For example, if I wanted to patch the source_object_start_timestamp variable, I would use: source_object_start_timestamp = patch('pandas.datetime.utcnow', return_value="2020-08-16 20:36:06.578174").start(). For BigQuery functions, I would still patch them but in your unit test, use the mock_call_count method of the unittest.mock.mock class to test if that function has been called.
Point 2 addresses your third query - use the mock_call_count method to check how many times the mock has been called

Create HEX attachment for Quality Notification

I have this piece of code to download the hex content of a file with import parameter file id. I want to insert a new attachment for a notification, but I don't know how to get started.
METHOD GET_SINGLE_ATTACHMENT_CONTENT.
" VARIABLES
DATA: HEXCONT TYPE TABLE OF SOLIX.
DATA: DOCDATA TYPE SOFOLENTI1.
DATA: LV_LENGTH TYPE I.
" CHECK TO CONTINUE FUNCTION MODULE
IF FILE_ID IS INITIAL. "type = SOFOLENTI1-DOC_ID.
MESSAGE 'Document ID is empty.' TYPE 'E' RAISING DOC_ID_EMPTY.
ENDIF.
" GET BINARY CONTENT OF FILE
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
DOCUMENT_ID = FILE_ID
IMPORTING
DOCUMENT_DATA = DOCDATA
TABLES
CONTENTS_HEX = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
" CONVERT TO XSTRING
LV_LENGTH = DOCDATA-DOC_SIZE.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = LV_LENGTH
IMPORTING
BUFFER = EV_RETURN "type XSTRING
TABLES
BINARY_TAB = HEXCONT.
IF SY-SUBRC <> 0.
MESSAGE 'Error downloading file.' TYPE 'E' RAISING FILE_DOWNLOAD_ERROR.
ENDIF.
ENDMETHOD.
I've read about function modules like 'SO_DOCUMENT_INSERT_API1' and it has the file information but not the file content (preferably hex content). Any idea on how to get started with this?
Maybe you can do something with the approach I used. Check this example below.
Start with parsing your data to hex
Insert the document with so_document_insert_api1
Link it to your notification with the fm binary_relation_create
" TYPES
TYPES: BEGIN OF TYPE_FILE,
NAME TYPE STRING,
TYPE TYPE STRING,
QMNUM TYPE QMNUM,
USER TYPE CHAR64,
HEXCONT TYPE XSTRING,
END OF TYPE_FILE.
" VARIABLES AND OBJECTS
DATA: LT_RETURN TYPE TABLE OF BAPIRET2.
DATA: LT_HEXCONT TYPE TABLE OF SOLIX.
DATA: LS_DOCDATA TYPE SODOCCHGI1.
DATA: LS_DOCINFO TYPE SOFOLENTI1.
DATA: LS_FILE TYPE TYPE_FILE.
DATA: LV_DOCTYPE TYPE SOODK-OBJTP.
DATA: LV_FOLDER_ID TYPE SOOBJINFI1-OBJECT_ID.
DATA: LV_LENGTH TYPE I.
DATA: OBJ_NOTIF TYPE BORIDENT.
DATA: OBJ_ATTACH TYPE BORIDENT.
DATA: P_QMNUM TYPE QMNUM.
LV_FOLDER_ID = 'FOL40000000000004'.
" CONVERT HEX CONTENT TO BINARY
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LS_FILE-HEXCONT
IMPORTING
OUTPUT_LENGTH = LV_LENGTH
TABLES
BINARY_TAB = LT_HEXCONT.
" SET VALUES
LS_DOCDATA-OBJ_DESCR = LS_FILE-NAME.
LS_DOCDATA-OBJ_LANGU = 'E'.
LS_DOCDATA-OBJ_NAME = 'MESSAGE'.
LS_DOCDATA-DOC_SIZE = XSTRLEN( LS_FILE-HEXCONT ).
LV_DOCTYPE = LS_FILE-TYPE.
UNPACK LS_FILE-QMNUM TO P_QMNUM.
" CREATE ATTACHMENT
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LS_DOCDATA
DOCUMENT_TYPE = LV_DOCTYPE
IMPORTING
DOCUMENT_INFO = LS_DOCINFO
TABLES
CONTENTS_HEX = LT_HEXCONT.
" CREATE LINK TO OBJECT (Notification)
OBJ_NOTIF-OBJKEY = P_QMNUM.
OBJ_NOTIF-OBJTYPE = 'BUS2038'.
OBJ_ATTACH-OBJKEY = LS_DOCINFO-DOC_ID.
OBJ_ATTACH-OBJTYPE = 'MESSAGE'.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
OBJ_ROLEA = OBJ_NOTIF
OBJ_ROLEB = OBJ_ATTACH
RELATIONTYPE = 'ATTA'.
" COMMIT
COMMIT WORK.
Is is necessary to open the contenct as hex?
You probably just want to read / write on a file. Try open OPEN DATASET
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapset_dataset.htm

HTTPS Communication Failure ABAP

I'm working on an application that should be connected to two web applications. The first web application is finished (http://example.com). Unfortunately, the second web application utilizing HTTPS (https://example.com) threw this error: Http_Communication_Failure SY-SUBRC = 1.
Here is my program:
FORM CHEKCV_LOG_PASS.
DATA : lv_flag TYPE flag,
iv_user TYPE CHAR20,
iv_pass TYPE CHAR20.
iv_user = 'username'.
iv_pass = 'Pw1-a83-333'.
IF sy-subrc IS NOT INITIAL.
ENDIF.
CONSTANTS: c_type_get VALUE 0,
c_type_post VALUE 1.
TYPES: BEGIN OF ty_parameter,
name TYPE string,
type TYPE char1,
value TYPE string,
END OF ty_parameter.
DATA ls_parameter TYPE ty_parameter.
DATA lt_parameters TYPE TABLE OF ty_parameter.
DATA lt_fields TYPE tihttpnvp.
DATA lv_url TYPE string.
DATA SOAP_ACTION TYPE string.
DATA lv_uri TYPE string.
DATA lv_value TYPE string.
DATA lv_name TYPE string.
DATA lt_html TYPE TABLE OF string.
DATA: lo_client TYPE REF TO if_http_client,
lc_content TYPE string,
xcontent_clear TYPE xstring,
contentencoding TYPE string.
DATA ls_field TYPE ihttpnvp.
DATA lc_url TYPE string.
DATA lv_user TYPE zvrs_veyes_user.
DATA lv_pass TYPE char32.
lv_user = iv_user.
lv_pass = iv_pass.
ls_parameter-name = '_username'.
ls_parameter-value = lv_user.
ls_parameter-type = c_type_post.
APPEND ls_parameter TO lt_parameters.
CLEAR ls_parameter.
ls_parameter-name = '_password'.
ls_parameter-value = lv_pass.
ls_parameter-type = c_type_post.
APPEND ls_parameter TO lt_parameters.
CLEAR ls_parameter.
LOOP AT lt_parameters INTO ls_parameter.
IF ls_parameter-type = c_type_post.
ls_field-name = ls_parameter-name.
ls_field-value = ls_parameter-value.
APPEND ls_field TO lt_fields.
ELSEIF ls_parameter-type = c_type_get.
IF lv_url = ''.
CONCATENATE '?' ls_parameter-name '=' ls_parameter-value
INTO lv_url.
ELSE.
CONCATENATE lv_url '&' ls_parameter-name '=' ls_parameter-value
INTO lv_url.
ENDIF.
ENDIF.
ENDLOOP.
lc_url = 'https://Example.com/login_check'.
CONCATENATE lc_url lv_url INTO lv_url.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_client
EXCEPTIONS
OTHERS = 1.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
******************************************************************
******************************************************************
LOOP AT lt_fields INTO ls_field.
lo_client->request->if_http_entity~set_form_field(
name = ls_field-name value = ls_field-value ).
ENDLOOP.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = lv_url.
lo_client->propertytype_accept_cookie = 1.
CALL METHOD lo_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
CALL METHOD lo_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'GET'.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = lc_url.
CALL METHOD lo_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
CALL METHOD lo_client->receive *HERE IS THE PROBLEME
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
lc_content = lo_client->response->get_cdata( ).
endform.
Check the system variables SY-MSGxx for more information on the actual problem. Most likely cause: The server certificate is not signed by any CA that the SAP system is configured to trust. You might have to add the server and/or CA certificates to the PSE. WARNING: Don't do that unless you know what you are doing and have cleared this with your basis admins/infosec officials or you might end up opening security leaks in a critical system.

How to display WebDynpro ABAP in ABAP report?

I've just started coding ABAP for a few days and I have a task to call the report from transaction SE38 and have
the report's result shown on the screen of the WebDynPro application SE80.
The report take the user input ( e.g: Material Number, Material Type, Plant, Sale Org. ) as a condition for querying, so the WebDynPro application must allow user to key in this parameters.
In some related article they were talking about using SUBMIT rep EXPORTING LIST TO MEMORY and CALL FUNCTION 'LIST_FROM_MEMORY' but so far I really have no idea to implement it.
Any answers will be appreciated. Thanks!
You can export it to PDF. Therefore, when a user clicks on a link, you run the conversion and display the file in the browser window.
To do so, you start by creating a JOB using the following code below:
constants c_name type tbtcjob-jobname value 'YOUR_JOB_NAME'.
data v_number type tbtcjob-jobcount.
data v_print_parameters type pri_params.
call function 'JOB_OPEN'
exporting
jobname = c_name
importing
jobcount = v_number
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
Then, you need to get the printer parameters in order to submit the report:
call function 'GET_PRINT_PARAMETERS'
exporting
destination = 'LP01'
immediately = space
new_list_id = 'X'
no_dialog = 'X'
user = sy-uname
importing
out_parameters = v_print_parameters
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
v_print_parameters-linct = 55.
v_print_parameters-linsz = 1.
v_print_parameters-paart = 'LETTER'.
Now you submit your report using the filters that apply. Do not forget to add the job parameters to it, as the code below shows:
submit your_report_name
to sap-spool
spool parameters v_print_parameters
without spool dynpro
with ...(insert all your filters here)
via job c_name number v_number
and return.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
After that, you close the job:
call function 'JOB_CLOSE'
exporting
jobcount = v_number
jobname = c_name
strtimmed = 'X'
exceptions
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
others = 8.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
Now the job will proceed and you'll need to wait for it to complete. Do it with a loop. Once the job is completed, you can get it's spool output and convert to PDF.
data v_rqident type tsp01-rqident.
data v_job_head type tbtcjob.
data t_job_steplist type tbtcstep occurs 0 with header line.
data t_pdf like tline occurs 0 with header line.
do 200 times.
wait up to 1 seconds.
call function 'BP_JOB_READ'
exporting
job_read_jobcount = v_number
job_read_jobname = c_name
job_read_opcode = '20'
importing
job_read_jobhead = v_job_head
tables
job_read_steplist = t_job_steplist
exceptions
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 3
others = 4.
read table t_job_steplist index 1.
if not t_job_steplist-listident is initial.
v_rqident = t_job_steplist-listident.
exit.
else.
clear v_job_head.
clear t_job_steplist.
clear t_job_steplist[].
endif.
enddo.
check not v_rqident is initial.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = v_rqident
dst_device = 'LP01'
tables
pdf = t_pdf
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
If you're going to send it via HTTP, you may need to convert it to BASE64 as well.
field-symbols <xchar> type x.
data v_offset(10) type n.
data v_char type c.
data v_xchar(2) type x.
data v_xstringdata_aux type xstring.
data v_xstringdata type xstring.
data v_base64data type string.
data v_base64data_aux type string.
loop at t_pdf.
do 134 times.
v_offset = sy-index - 1.
v_char = t_pdf+v_offset(1).
assign v_char to <xchar> casting type x.
concatenate v_xstringdata_aux <xchar> into v_xstringdata_aux in byte mode.
enddo.
concatenate v_xstringdata v_xstringdata_aux into v_xstringdata in byte mode.
clear v_xstringdata_aux.
endloop.
call function 'SCMS_BASE64_ENCODE_STR'
exporting
input = v_xstringdata
importing
output = v_base64data.
v_base64data_aux = v_base64data.
while strlen( v_base64data_aux ) gt 255.
clear t_base64data.
t_base64data-data = v_base64data_aux.
v_base64data_aux = v_base64data_aux+255.
append t_base64data.
endwhile.
if not v_base64data_aux is initial.
t_base64data-data = v_base64data_aux.
append t_base64data.
endif.
And you're done!
Hope it helps.
As previous speakers said, you should do extensive training before implementing such stuff in productive environment.
However, calling WebdynPro ABAP within report can be done with the help of WDY_EXECUTE_IN_PLACE function module. You should pass there Webdyn Pro application and necessary parameters.
CALL FUNCTION 'WDY_EXECUTE_IN_PLACE'
EXPORTING
* PROTOCOL =
INTERNALMODE = ' '
* SMARTCLIENT =
APPLICATION = 'Z_MY_WEBDYNPRO'
* CONTAINER_NAME =
PARAMETERS = lt_parameters
SUPPRESS_OUTPUT =
TRY_TO_USE_SAPGUI_THEME = ' '
IMPORTING
OUT_URL = ex_url
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

IndexError: list index out of range, scores.append( (fields[0], fields[1]))

I'm trying to read a file and put contents in a list. I have done this mnay times before and it has worked but this time it throws back the error "list index out of range".
the code is:
with open("File.txt") as f:
scores = []
for line in f:
fields = line.split()
scores.append( (fields[0], fields[1]))
print(scores)
The text file is in the format;
Alpha:[0, 1]
Bravo:[0, 0]
Charlie:[60, 8, 901]
Foxtrot:[0]
I cant see why it is giving me this problem. Is it because I have more than one value for each item? Or is it the fact that I have a colon in my text file?
How can I get around this problem?
Thanks
If I understand you well this code will print you desired result:
import re
with open("File.txt") as f:
# Let's make dictionary for scores {name:scores}.
scores = {}
# Define regular expressin to parse team name and team scores from line.
patternScore = '\[([^\]]+)\]'
patternName = '(.*):'
for line in f:
# Find value for team name and its scores.
fields = re.search(patternScore, line).groups()[0].split(', ')
name = re.search(patternName, line).groups()[0]
# Update dictionary with new value.
scores[name] = fields
# Print output first goes first element of keyValue in dict then goes keyName
for key in scores:
print (scores[key][0] + ':' + key)
You will recieve following output:
60:Charlie
0:Alpha
0:Bravo
0:Foxtrot

Resources