Using Your Liquid UI Products > WS aka Web Scripts (Attended RPA for SAP)
Liquid UI: Convert function module structure detail to type object
(1/1)
Leo Chu:
Liquid UI: Convert function module structure detail to type object
This example is to convert function module structure detail to a type object, which is required when Use call command to get native SAP function module detail.
For each function module structure, it needs specific type object for call command to reference.
--- Quote --- var z_STRUCTURE_NAME = {
name:STRUCTURE_NAME,
components:[
{ name:COMPONENT_NAME, length:DATA_LENGTH, decimalpl:DECIMAL_POINT_LENGTH, type:DATA_TYPE },
...
]
};
--- End quote ---
In type object, each component has different ABAP data type, which can be referenced from below table.
LUI Type ABAP Type Data Type Description b'b'INT1Cannot be substituted with 'C'C'C'CHAR, UNIT, LANG, CUKY, LCHR D'D'DATSCan be substituted with 'C' When used as 'D', the Component will be a JavaScript Date object, whereas, if specified as 'C', it will be a string returned by SAP in the format of "19941107"F or f'F'FLTPCannot be substituted with 'C' For BAPI FM, specify LUI type as "F"; for FM RFC_READ_TABLE, specify LUI type as "f"T'T'TIMSCurrently same as 'C' and can be substituted with 'C'N'N'NUMCCan be substituted with 'C'P or f'P'QUAN, DEC, CURRCannot be substituted with 'C' For BAPI FM, specify LUI type as "P"; for FM RFC_READ_TABLE, specify LUI type as "f"s or i's'INT2Cannot be substituted with 'C' For BAPI FM, specify LUI type as "s"; for FM RFC_READ_TABLE, specify LUI type as "i"I'I'INT, INT4Cannot be substituted with 'C'
Step 1: Check output structure according to parameter
The structure of each output parameter needs to be specified individually.
Its detail can be referenced from SAP in transaction SE37 follow by below steps.
1. On initial screen of SE37, enter the FM
2. Click on "Display" button to check detail
3. On the display screen, select "Export" or "Tables" tab according to your output
4. In corresponding tab, find the row of output parameter and double click on it to see detail structure
5. Stay in the structure detail screen, and prepare to create the script based on the screen
Use FM BAPI_ALM_ORDER_GET_DETAIL as an example, its ES_HEADER parameter has structure BAPI_ALM_ORDER_HEADER_E which SAP screen should shown as below.
Component Typing Method Component Type Data Type Length Decimal Pl Short Description ORDERID1AUFNRCHAR120Order NumberORDER_TYPE1AUFARTCHAR40Order TypePLANPLANT1IWERKCHAR40Maintenance Planning PlantBUS_AREA1GSBERCHAR40Business AreaMN_WK_CTR1GEWRKCHAR80Main work center for maintenance tasksPLANT1WERGWCHAR40Plant associated with main work centerMN_WKCTR_ID1LGWIDNUMC80Object ID of the Work CenterPMACTTYPE1ILACHAR30Maintenance activity typePLANGROUP1INGRPCHAR30Planner Group for Customer Service and Plant MaintenanceSYSTCOND1ANLZUCHAR10Syst.ConditionFUNCT_LOC1TPLNRCHAR300Functional LocationEQUIPMENT1EQUNRCHAR180Equipment NumberSERIALNO1GERNRCHAR180Serial NumberMATERIAL1MATNRCHAR180Material NumberASSEMBLY1BAUTLCHAR180AssemblyDEVICEDATA1DEVICEIDCHAR400Additional Device DataMAINTPLANT1SWERKCHAR40Maintenance plantLOCATION1STORTCHAR100Asset locationMAINTROOM1RAUMNRCHAR80RoomPLSECTN1BEBERCHAR30Plant sectionLOC_WK_CTR1ARBPLCHAR80Work centerLOC_WKCTR_ID1PPSIDNUMC80Object ID of PP work centerABCINDIC1ABCKZCHAR10ABC indicator for technical objectSORTFIELD1EQFNRCHAR300Sort fieldCOMP_CODE1BUKRSCHAR40Company CodePROFIT_CTR1PRCTRCHAR100Profit CenterCO_AREA1KOKRSCHAR40Controlling AreaRESPCCTR1AUFKOSTVCHAR100Responsible cost centerFUNC_AREA1FKBERCHAR160Functional AreaSUPERIOR_NETWORK1CO_TEILNETCHAR120Number of superior networkSUPERIOR_ACTIVITY1CN_VORNRCHAR40Activity number in network and standard networkSUPERIOR_ROUTING_NO1CO_AUFPLNUMC100Routing number of operations in the orderSUPERIOR_COUNTER1CO_APLZLNUMC80General counter for orderWBS_ELEM1PS_PSP_PNRNUMC80Work Breakdown Structure Element (WBS Element)PROJ_DEF1PS_PSP_PRONUMC80Project definitionPROCESSING_GROUP1AUFABKRSNUMC20Processing groupOBJECTCLASS1SCOPE_CVCHAR20Object ClassTAXJURCODE1TXJCDCHAR150Tax JurisdictionLOC_COMP_CODE1BUKRSCHAR40Company CodeLOC_CO_AREA1KOKRSCHAR40Controlling AreaASSET_NO1ANLN1CHAR120Main Asset NumberSUB_NUMBER1ANLN2CHAR40Asset SubnumberLOC_BUS_AREA1GSBERCHAR40Business AreaCOSTCENTER1KOSTLCHAR100Cost CenterLOC_WBS_ELEM1PS_PSP_PNRNUMC80Work Breakdown Structure Element (WBS Element)STANDORDER1DAUFNCHAR120Standing order numberSETTLORDER1ILOM_ORDSTCHAR120Settlement orderSALESORG1VKORGCHAR40Sales OrganizationDISTR_CHAN1VTWEGCHAR20Distribution ChannelDIVISION1SPARTCHAR20DivisionORDPLANID1AUF_PLKNZCHAR10Maintenance order planning indicatorSTART_DATE1CO_GSTRPDATS80Basic start dateFINISH_DATE1CO_GLTRPDATS80Basic finish dateBASICSTART1CO_GSUZPTIMS60Basic start timeBASIC_FIN1CO_GLUZPTIMS60Basic finish (time)PRIORITY1PRIOKCHAR10PriorityREVISION1REVNICHAR80Revision for Plant Maintenance and Customer ServiceVERSION1KAPVERSANUMC20Version of Available CapacitySCHED_TYPE1TERMKZCHAR10Scheduling typeAUTOSCHED1CO_AUTERMCHAR10Indicator: Schedule automaticallyCAP_REQMTS1AUKBEDCHAR10Indicator: Calculate capacity requirementsSCHEDULING_EXACT_BREAK_TIMES1BREAKSCHAR10Indicator: Scheduling allowing for breaksMRP_RELEVANT1AUDISP_PLUSCHAR10Reservation Relevance/Generation of Purchase RequisitionPRODUCTION_START_DATE1CO_GSTRSDATS80Scheduled startPRODUCTION_FINISH_DATE1CO_GLTRSDATS80Scheduled finishPRODUCTION_START_TIME1CO_GSUZSTIMS60Scheduled Start (Time)PRODUCTION_FINISH_TIME1CO_GLUZSTIMS60Scheduled finish timeACTUAL_START_DATE1CO_GSTRIDATS80Actual start dateACTUAL_FINISH_DATE1CO_GETRIDATS80Confirmed Order Finish DateACTUAL_START_TIME1CO_GSUZITIMS60Actual start timeACTUAL_FINISH_TIME1CO_GEUZITIMS60Confirmed order finish (time)REFDATE1ADDATDATS80PM Order: Reference DateSALES_ORD1KDAUFCHAR100Sales Order NumberS_ORD_ITEM1KDPOSNUMC60Item Number in Sales OrderCALC_MOTIVE1BEMOTCHAR20Accounting IndicatorINVEST_PROFILE1IM_PROFILCHAR60Investment measure profileSCALE1IM_SIZECLCHAR20Scale of investment objectsINV_REASON1IZWEKCHAR20Reason for investmentENVIR_INVEST1AM_UMWKZCHAR50Reason for environmental investmentESTIMATED_COSTS1AUFUSER4CURR112Estimated total costs of orderCURRENCY1AUFWAERSCUKY50Order CurrencyCURRENCY_ISO1ISOCDCHAR30ISO currency codeCSTG_SHEET1AUFKALSMCHAR60Costing SheetOVERHEAD_KEY1AUFZSCHLCHAR60Overhead keyRES_ANAL_KEY1ABGR_SCHLCHAR60Results Analysis KeyNETWORK_PROFILE1PROFIDNZPLCHAR70Network profileCSTGVAPPLN1KALKVARPLNCHAR40Costing variant for planned costsCSTGVARACT1KALKVARISTCHAR40Costing variant for actual costsTASK_LIST_GROUP1PLNNRCHAR80Key for Task List GroupGROUP_COUNTER1PLNALCHAR20Group CounterTASK_LIST_TYPE1PLNTYCHAR10Task List TypeRESP_PLANNER_GROUP1VAGRPCHAR30Responsible planner group/departmentMNTPLAN1WARPLCHAR120Maintenance PlanMAINTITEM1WAPOSCHAR160Maintenance itemCALL_NO1ABNUMINT4100Maintenance Plan Call NumberLAST_ORD1LAUFNCHAR120Order numberENTERED_BY1AUFERFNAMCHAR120Entered byENTER_DATE1AUFERFDATDATS80Created onCHANGED_BY1AUFAENAMCHAR120Last changed byCHANGE_DATE1AUFAEDATDATS80Change date for Order MasterSCENARIO1SCRTPCHAR40Scenario or Subscreen CategorySYS_STATUS1CO_STTXTCHAR400System StatusUSER_ST1CO_ASTEXCHAR10User status activeUSERSTATUS1CO_ASTTXCHAR400Field displaying user statusSTAT_PROF1J_STSMACHAR80Status ProfileOBJECT_NO1J_OBJNRCHAR220Object numberROUTING_NO1CO_AUFPLNUMC100Routing number of operations in the orderRESERV_NO1RSNUMNUMC100Number of Reservation/Dependent RequirementSHORT_TEXT1AUFTEXTCHAR400DescriptionLONG_TEXT1CO_LTEXTCHAR10Long text existsNOTIF_NO1QMNUMCHAR120Notification NoASSEMBLY_EXTERNAL1MGV_ASSEMBLY_EXTERNALCHAR400Long Material Number for Field ASSEMBLYASSEMBLY_GUID1MGV_ASSEMBLY_GUIDCHAR320External GUID for ASSEMBLY FieldASSEMBLY_VERSION1MGV_ASSEMBLY_VERSIONCHAR100Version Number for ASSEMBLY FieldMATERIAL_EXTERNAL1MGV_MATERIAL_EXTERNALCHAR400Long Material Number for MATERIAL FieldMATERIAL_GUID1MGV_MATERIAL_GUIDCHAR320External GUID for MATERIAL FieldMATERIAL_VERSION1MGV_MATERIAL_VERSIONCHAR100Version Number for MATERIAL FieldCALID1WFCIDCHAR20Factory CalendarKALSN1KALSNNUMC20Calendar Selection for OrderSUPERIOR_ORDERID1MAUFNRCHAR120Number of superior orderLEADING_ORDERID1CO_LAUFNRCHAR120Leading order in current processingSTART_POINT1EAML_START_POINTCHAR180Start PointEND_POINT1EAML_END_POINTCHAR180End PointLINEAR_LENGTH1EAML_LINEAR_LENGTHCHAR180LengthLINEAR_UNIT1EAML_LINEAR_UNITUNIT30Unit of Measurement for Linear DataLINEAR_UNIT_ISO1EAML_LINEAR_UNIT_ISOCHAR30Unit of Measurement for Linear Data in ISO CodeFIRST_OFFSET_TYPE_CODE1EAML_OFFSET1_TYPE_CODECHAR20Type of First OffsetFIRST_OFFSET_VALUE1EAML_OFFSET1_VALUECHAR180Value of Offset 1FIRST_OFFSET_UNIT1EAML_OFFSET1_UNITUNIT30Unit of Measurement for Offset 1FIRST_OFFSET_UNIT_ISO1EAML_OFFSET1_UNIT_ISOCHAR30Unit of Measurement for Offset 1 in ISO CodeSECOND_OFFSET_TYPE_CODE1EAML_OFFSET2_TYPE_CODECHAR20Type of Second OffsetSECOND_OFFSET_VALUE1EAML_OFFSET2_VALUECHAR180Value of Offset 2SECOND_OFFSET_UNIT1EAML_OFFSET2_UNITUNIT30Unit of Measurement for Offset 2SECOND_OFFSET_UNIT_ISO1EAML_OFFSET2_UNIT_ISOCHAR30Unit of Measurement for Offset 2 in ISO CodeFIRST_OFFSET_TYPE_CODE_NAME1EAML_OFFSET1_TYPE_CODE_NAMECHAR600First Offset Type DescriptionSECOND_OFFSET_TYPE_CODE_NAME1EAML_OFFSET2_TYPE_CODE_NAMECHAR600Second Offset Type DescriptionMARKER_START_POINT1EAML_MARKER_START_POINTCHAR180Marker for Start PointMARKER_DISTANCE_START_POINT1EAML_MARKER_DISTANCE_STARTCHAR180Distance between Marker and Start PointMARKER_END_POINT1EAML_MARKER_END_POINTCHAR180Marker for End PointMARKER_DISTANCE_END_POINT1EAML_MARKER_DISTANCE_ENDCHAR180Length Spec for Distance between Marker and End PointMARKER_DISTANCE_UNIT1EAML_MARKER_DISTANCE_UNITUNIT30Unit for the Distance from MarkerMARKER_DISTANCE_UNIT_ISO1EAML_MARKER_DISTANCE_UNIT_ISOCHAR30Unit for the Distance from Marker in ISO CodePRIOTYPE1ARTPRCHAR20Priority Type
Note: Use "Ctrl+Y" can select table content from SAP GUI, then use "Ctrl+C" to copy
Step 2: Create lookup dictionary for different data type
According to different ABAP data types, we need to create a lookup dictionary when generating the structure object.
--- Quote ---DATA_TYPE_REF_ARY = {
"CHAR":"C", "UNIT":"C", "LANG":"C", "CUKY":"C", "LCHR":"C",
"DATS":"D", "FLTP":"F", "TIMS":"T", "NUMC":"N",
"QUAN":"P", "DEC":"P", "CURR":"P",
"INT":"I", "INT1":"b", "INT2":"s", "INT4":"I"
};
--- End quote ---
Step 3: Create custom layout on the screen
--- Quote ---//Make sure this layout will only show in transaction SE37
if(_transaction == "SE37"){
if(!z_se37_display_structure_obj){
pushbutton([TOOLBAR], "Get Structure Object", "?", {"process":se37GetStructureObject}); //Trigger the function to generate structure object detail
}
else {
pushbutton([TOOLBAR], "Clear Structure Object", "?", {"process":se37Reset}); //Trigger the function to reset all realted variables
clearscreen();
textbox([0,0], [30,200], {"name":"z_se37_structure_obj_text"}); //Textbox to display result structure object detail
}
}
--- End quote ---
Step 4: Create function to reset SE37 related variables
--- Quote ---function se37Reset(){
set("V[z_se37*]", "");
}
--- End quote ---
Step 5: Create function to read the component table and return structure object detail
--- Quote ---function se37GetStructureObject(){
onscreen "SAPLSD41.2100"
set("V[z_se37_structure]", "&F[Structure]"); //Read the structure value
var relrow = 1;
var absrow = 1;
var z_se37_component_ary = [];
var z_se37_row_ary = [];
NEW_SCREEN:;
enter("/ScrollToLine=&V[absrow]", {"table":"T[SAPLSD41_TC0]"});
onscreen "SAPLSD41.2100"
gettableattribute("T[SAPLSD41_TC0]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LRow"});
relrow = 1;
NEW_ROW:;
if(absrow > LVisRow){
goto NEW_SCREEN;
}
if(absrow > LRow){
goto END_OF_TABLE;
}
z_se37_row_ary = [];
//Read each row of component table
set("V[cur_component]", "&cell[SAPLSD41_TC0,Component,&V[relrow]]");
set("V[cur_typing_method]", "&cell[SAPLSD41_TC0,Typing Method,&V[relrow]]");
set("V[cur_component_type]", "&cell[SAPLSD41_TC0,Component Type,&V[relrow]]");
set("V[cur_data_type]", "&cell[SAPLSD41_TC0,Data Type,&V[relrow]]");
set("V[cur_length]", "&cell[SAPLSD41_TC0,Length,&V[relrow]]");
set("V[cur_decimal_pl]", "&cell[SAPLSD41_TC0,Decimal Pl,&V[relrow]]");
set("V[cur_short_desc]", "&cell[SAPLSD41_TC0,Short Description,&V[relrow]]");
z_se37_row_ary.push(cur_component);
z_se37_row_ary.push(cur_typing_method);
z_se37_row_ary.push(cur_component_type);
z_se37_row_ary.push(cur_data_type);
z_se37_row_ary.push(cur_length);
z_se37_row_ary.push(cur_decimal_pl);
z_se37_row_ary.push(cur_short_desc);
z_se37_component_ary.push(z_se37_row_ary);
relrow++;
absrow++;
goto NEW_ROW;
END_OF_TABLE:;
//Change flag to display the result textbox
z_se37_display_structure_obj = true;
//Get organized structure object detail
var z_se37_result_struct_ary = setStructureObject(z_se37_structure,z_se37_component_ary); //Get organized result array from function
//Logic to copy content from organized result array to longtext variable
for(var struct in z_se37_result_struct_ary){
tmp_str = z_se37_result_struct_ary[struct];
if(struct==0)
copytext({"totext":"z_se37_structure_obj_text", "fromstring":"tmp_str"});
else
copytext({"totext":"z_se37_structure_obj_text", "fromstring":"tmp_str", "appendline":true});
}
enter("/ScrollToLine=1", {"table":"T[SAPLSD41_TC0]"});
}
--- End quote ---
Step 6: Create function to organized fetched table data
--- Quote ---function setStructureObject(structure,component_ary){
var result_ary = [];
var component_str = "";
result_ary.push("\tvar z_" + structure + " = {\n"); //Decalre the type object
result_ary.push("\t\tname:'" + structure + "',\n"); //Add the name variable
result_ary.push("\t\tcomponents:[\n"); //Add the components object
for(var i=0; i<component_ary.length; i++){ //For loop to form each component
component_str = "\t\t\t{ name:'" + component_ary[0] +
"', \tlength:" + component_ary[4] +
",\tdecimalpl:" + component_ary[5] +
",\ttype:'" + DATA_TYPE_REF_ARY[component_ary[3]] +
"' }" + ((i!=component_ary.length-1)?",\n":"\n") +
"\t" + ((component_ary[3]=="CHAR")?"\t\t\t\t":("/** " + component_ary[3] + " **/\t\t\t")) +
"//" + component_ary[6];
result_ary.push(component_str);
}
result_ary.push("\t\t]\n"); //End component object
result_ary.push("\t};"); //End type object
return result_ary;
}
--- End quote ---
Step 7: Copy result to your script
After execution, the result of structure object should displayed in the textbox.
Now select everything from the textbox and copy to the targeting script.
See attachments for full script example
Navigation
[0] Message Index
Go to full version