ABAP Select data from SAP table BAPI1172_LIST_ALL into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP BAPI1172_LIST_ALL table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to BAPI1172_LIST_ALL. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the BAPI1172_LIST_ALL table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_BAPI1172_LIST_ALL TYPE STANDARD TABLE OF BAPI1172_LIST_ALL, WA_BAPI1172_LIST_ALL TYPE BAPI1172_LIST_ALL, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <BAPI1172_LIST_ALL> TYPE BAPI1172_LIST_ALL. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI1172_LIST_ALL. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI1172_LIST_ALL INTO TABLE IT_BAPI1172_LIST_ALL. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI1172_LIST_ALL * INTO TABLE @DATA(IT_BAPI1172_LIST_ALL2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_BAPI1172_LIST_ALL INDEX 1 INTO DATA(WA_BAPI1172_LIST_ALL2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI1172_LIST_ALL ASSIGNING <BAPI1172_LIST_ALL>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI1172_LIST_ALL>-KANBANCONTROLCYCLE = 1.
<BAPI1172_LIST_ALL>-MATERIAL = 1.
<BAPI1172_LIST_ALL>-PLANT = 1.
<BAPI1172_LIST_ALL>-SUPPLYAREA = 1.
<BAPI1172_LIST_ALL>-KANBAN_CT = 1.
ENDLOOP. LOOP AT IT_BAPI1172_LIST_ALL INTO WA_BAPI1172_LIST_ALL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI1172_LIST_ALL-KANBAN_QTY, sy-vline,
WA_BAPI1172_LIST_ALL-VERSION, sy-vline,
WA_BAPI1172_LIST_ALL-MAX_EMPTY, sy-vline,
WA_BAPI1172_LIST_ALL-RESP_SUPPLY_SOURCE, sy-vline,
WA_BAPI1172_LIST_ALL-STRATEGY_INHOUSE_PROD, sy-vline,
WA_BAPI1172_LIST_ALL-MAT_STAG_INDICATOR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI1172_LIST_ALL you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_BAPI1172_LIST_ALL TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_BAPI1172_LIST_ALL INTO WA_BAPI1172_LIST_ALL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ALPHA, internal->external for field KANBANCONTROLCYCLE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-KANBANCONTROLCYCLE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-KANBANCONTROLCYCLE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN5, internal->external for field MATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN5_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-MATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-MATERIAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VENDOR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-VENDOR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-VENDOR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AGREEMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-AGREEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-AGREEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN5, internal->external for field KANBANCONTAINER CALL FUNCTION 'CONVERSION_EXIT_MATN5_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-KANBANCONTAINER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-KANBANCONTAINER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BASE_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-BASE_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-BASE_UOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-COSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-COSTCENTER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit SPDEV, internal->external for field OUTPUT_DEVICE CALL FUNCTION 'CONVERSION_EXIT_SPDEV_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-OUTPUT_DEVICE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-OUTPUT_DEVICE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DELIV_ADDR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-DELIV_ADDR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-DELIV_ADDR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTRN, internal->external for field REPL_LEADTIME_MIN CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-REPL_LEADTIME_MIN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-REPL_LEADTIME_MIN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SD_SCHED_AGRMNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-SD_SCHED_AGRMNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-SD_SCHED_AGRMNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PACKINSTRID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-PACKINSTRID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-PACKINSTRID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field REP_POINT CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-REP_POINT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-REP_POINT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNL, internal->external for field MATERIAL_EXTERNAL CALL FUNCTION 'CONVERSION_EXIT_MATNL_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-MATERIAL_EXTERNAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-MATERIAL_EXTERNAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNW, internal->external for field MATERIAL_VERSION CALL FUNCTION 'CONVERSION_EXIT_MATNW_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-MATERIAL_VERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-MATERIAL_VERSION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNL, internal->external for field KANBANCONTAINER_EXTERNAL CALL FUNCTION 'CONVERSION_EXIT_MATNL_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-KANBANCONTAINER_EXTERNAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-KANBANCONTAINER_EXTERNAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNW, internal->external for field KANBANCONTAINER_VERSION CALL FUNCTION 'CONVERSION_EXIT_MATNW_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-KANBANCONTAINER_VERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-KANBANCONTAINER_VERSION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATERIAL_LONG CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-MATERIAL_LONG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-MATERIAL_LONG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field KANBANCONTAINER_LONG CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_BAPI1172_LIST_ALL-KANBANCONTAINER_LONG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1172_LIST_ALL-KANBANCONTAINER_LONG.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_BAPI1172_LIST_ALL_STR,
KANBANCONTROLCYCLE TYPE STRING,
MATERIAL TYPE STRING,
PLANT TYPE STRING,
SUPPLYAREA TYPE STRING,
KANBAN_CT TYPE STRING,
KANBAN_QTY TYPE STRING,
VERSION TYPE STRING,
MAX_EMPTY TYPE STRING,
RESP_SUPPLY_SOURCE TYPE STRING,
STRATEGY_INHOUSE_PROD TYPE STRING,
MAT_STAG_INDICATOR TYPE STRING,
WHSENUMBER TYPE STRING,
STGE_TYPE TYPE STRING,
STGE_BIN TYPE STRING,
DYN_DESTINATION_BIN TYPE STRING,
STRATEGY_EXT_REPL TYPE STRING,
STRATEGY_STOCK_TRANSF TYPE STRING,
VENDOR TYPE STRING,
PURCH_ORG TYPE STRING,
AGREEMENT TYPE STRING,
AGRMT_ITEM TYPE STRING,
INDEP_REPL TYPE STRING,
KANBANCONTAINER TYPE STRING,
SEPARATE_GR_IF_FULL TYPE STRING,
STGE_LOC TYPE STRING,
BASE_UOM TYPE STRING,
BASE_UOM_ISO TYPE STRING,
CC_STATUS TYPE STRING,
COSTCENTER TYPE STRING,
OUTPUT_DEVICE TYPE STRING,
KANBAN_PRINT_CONTROL TYPE STRING,
ISSUINGPLANT TYPE STRING,
DELIV_ADDR TYPE STRING,
STAT_SEQ TYPE STRING,
LOGIC_SET_EMPTY TYPE STRING,
TRIGGER_QTY TYPE STRING,
STORING_POS TYPE STRING,
CC_CALCU_INDEX TYPE STRING,
SAFTYFACTOR TYPE STRING,
CONST_KANBAN_CALC TYPE STRING,
ROUNDING_QTY TYPE STRING,
FIX_KANBAN_QTY TYPE STRING,
KANBAN_CALC_PROF TYPE STRING,
REPL_LEADTIME_DAY TYPE STRING,
REPL_LEADTIME_MIN TYPE STRING,
SD_SCHED_AGRMNT TYPE STRING,
SD_SCHED_AGRMNT_ITEM TYPE STRING,
SOURCE_SUPP_AREA TYPE STRING,
JIT_CALL_PROF TYPE STRING,
INTERNAL_PACK_OBJ TYPE STRING,
NUMBER_LOADCARRIER TYPE STRING,
CC_CARD TYPE STRING,
MATL_DESC TYPE STRING,
PLANT_DESC TYPE STRING,
SUPPLYAREA_DESC TYPE STRING,
STRATEGY_INHOUSE_DESC TYPE STRING,
STRATEGY_EXT_REPL_DESC TYPE STRING,
STRATEGY_STOCK_TRANSF_DESC TYPE STRING,
PACKINSTRID TYPE STRING,
KANBANCONTAINER_DESC TYPE STRING,
REP_POINT TYPE STRING,
MATERIAL_EXTERNAL TYPE STRING,
MATERIAL_VERSION TYPE STRING,
MATERIAL_GUID TYPE STRING,
KANBANCONTAINER_EXTERNAL TYPE STRING,
KANBANCONTAINER_VERSION TYPE STRING,
KANBANCONTAINER_GUID TYPE STRING,
LIFECYCLE_STATUS TYPE STRING,
CREATION_DATE TYPE STRING,
RELEASE_DATE TYPE STRING,
LOCK_DATE TYPE STRING,
MATERIAL_LONG TYPE STRING,
KANBANCONTAINER_LONG TYPE STRING,
DESTINATION_STORAGE_BIN TYPE STRING,
SOURCE_STORAGE_BIN TYPE STRING,
WAREHOUSE_PROCESS_TYPE TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI1172_LIST_ALL_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTROLCYCLE sy-vline
WA_BAPI1172_LIST_ALL_STR-MATERIAL sy-vline
WA_BAPI1172_LIST_ALL_STR-PLANT sy-vline
WA_BAPI1172_LIST_ALL_STR-SUPPLYAREA sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBAN_CT sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBAN_QTY sy-vline
WA_BAPI1172_LIST_ALL_STR-VERSION sy-vline
WA_BAPI1172_LIST_ALL_STR-MAX_EMPTY sy-vline
WA_BAPI1172_LIST_ALL_STR-RESP_SUPPLY_SOURCE sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_INHOUSE_PROD sy-vline
WA_BAPI1172_LIST_ALL_STR-MAT_STAG_INDICATOR sy-vline
WA_BAPI1172_LIST_ALL_STR-WHSENUMBER sy-vline
WA_BAPI1172_LIST_ALL_STR-STGE_TYPE sy-vline
WA_BAPI1172_LIST_ALL_STR-STGE_BIN sy-vline
WA_BAPI1172_LIST_ALL_STR-DYN_DESTINATION_BIN sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_EXT_REPL sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_STOCK_TRANSF sy-vline
WA_BAPI1172_LIST_ALL_STR-VENDOR sy-vline
WA_BAPI1172_LIST_ALL_STR-PURCH_ORG sy-vline
WA_BAPI1172_LIST_ALL_STR-AGREEMENT sy-vline
WA_BAPI1172_LIST_ALL_STR-AGRMT_ITEM sy-vline
WA_BAPI1172_LIST_ALL_STR-INDEP_REPL sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER sy-vline
WA_BAPI1172_LIST_ALL_STR-SEPARATE_GR_IF_FULL sy-vline
WA_BAPI1172_LIST_ALL_STR-STGE_LOC sy-vline
WA_BAPI1172_LIST_ALL_STR-BASE_UOM sy-vline
WA_BAPI1172_LIST_ALL_STR-BASE_UOM_ISO sy-vline
WA_BAPI1172_LIST_ALL_STR-CC_STATUS sy-vline
WA_BAPI1172_LIST_ALL_STR-COSTCENTER sy-vline
WA_BAPI1172_LIST_ALL_STR-OUTPUT_DEVICE sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBAN_PRINT_CONTROL sy-vline
WA_BAPI1172_LIST_ALL_STR-ISSUINGPLANT sy-vline
WA_BAPI1172_LIST_ALL_STR-DELIV_ADDR sy-vline
WA_BAPI1172_LIST_ALL_STR-STAT_SEQ sy-vline
WA_BAPI1172_LIST_ALL_STR-LOGIC_SET_EMPTY sy-vline
WA_BAPI1172_LIST_ALL_STR-TRIGGER_QTY sy-vline
WA_BAPI1172_LIST_ALL_STR-STORING_POS sy-vline
WA_BAPI1172_LIST_ALL_STR-CC_CALCU_INDEX sy-vline
WA_BAPI1172_LIST_ALL_STR-SAFTYFACTOR sy-vline
WA_BAPI1172_LIST_ALL_STR-CONST_KANBAN_CALC sy-vline
WA_BAPI1172_LIST_ALL_STR-ROUNDING_QTY sy-vline
WA_BAPI1172_LIST_ALL_STR-FIX_KANBAN_QTY sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBAN_CALC_PROF sy-vline
WA_BAPI1172_LIST_ALL_STR-REPL_LEADTIME_DAY sy-vline
WA_BAPI1172_LIST_ALL_STR-REPL_LEADTIME_MIN sy-vline
WA_BAPI1172_LIST_ALL_STR-SD_SCHED_AGRMNT sy-vline
WA_BAPI1172_LIST_ALL_STR-SD_SCHED_AGRMNT_ITEM sy-vline
WA_BAPI1172_LIST_ALL_STR-SOURCE_SUPP_AREA sy-vline
WA_BAPI1172_LIST_ALL_STR-JIT_CALL_PROF sy-vline
WA_BAPI1172_LIST_ALL_STR-INTERNAL_PACK_OBJ sy-vline
WA_BAPI1172_LIST_ALL_STR-NUMBER_LOADCARRIER sy-vline
WA_BAPI1172_LIST_ALL_STR-CC_CARD sy-vline
WA_BAPI1172_LIST_ALL_STR-MATL_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-PLANT_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-SUPPLYAREA_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_INHOUSE_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_EXT_REPL_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-STRATEGY_STOCK_TRANSF_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-PACKINSTRID sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER_DESC sy-vline
WA_BAPI1172_LIST_ALL_STR-REP_POINT sy-vline
WA_BAPI1172_LIST_ALL_STR-MATERIAL_EXTERNAL sy-vline
WA_BAPI1172_LIST_ALL_STR-MATERIAL_VERSION sy-vline
WA_BAPI1172_LIST_ALL_STR-MATERIAL_GUID sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER_EXTERNAL sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER_VERSION sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER_GUID sy-vline
WA_BAPI1172_LIST_ALL_STR-LIFECYCLE_STATUS sy-vline
WA_BAPI1172_LIST_ALL_STR-CREATION_DATE sy-vline
WA_BAPI1172_LIST_ALL_STR-RELEASE_DATE sy-vline
WA_BAPI1172_LIST_ALL_STR-LOCK_DATE sy-vline
WA_BAPI1172_LIST_ALL_STR-MATERIAL_LONG sy-vline
WA_BAPI1172_LIST_ALL_STR-KANBANCONTAINER_LONG sy-vline
WA_BAPI1172_LIST_ALL_STR-DESTINATION_STORAGE_BIN sy-vline
WA_BAPI1172_LIST_ALL_STR-SOURCE_STORAGE_BIN sy-vline
WA_BAPI1172_LIST_ALL_STR-WAREHOUSE_PROCESS_TYPE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.