ABAP Select data from SAP table ICNTWCSTA1 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 ICNTWCSTA1 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 ICNTWCSTA1. 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 ICNTWCSTA1 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_ICNTWCSTA1 TYPE STANDARD TABLE OF ICNTWCSTA1, WA_ICNTWCSTA1 TYPE ICNTWCSTA1, 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: <ICNTWCSTA1> TYPE ICNTWCSTA1. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_ICNTWCSTA1. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM ICNTWCSTA1 INTO TABLE IT_ICNTWCSTA1. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM ICNTWCSTA1 * INTO TABLE @DATA(IT_ICNTWCSTA12). *--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_ICNTWCSTA1 INDEX 1 INTO DATA(WA_ICNTWCSTA12). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_ICNTWCSTA1 ASSIGNING <ICNTWCSTA1>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<ICNTWCSTA1>-KOKRS = 1.
<ICNTWCSTA1>-BELNR = 1.
<ICNTWCSTA1>-BUZEI = 1.
<ICNTWCSTA1>-FISCVAR = 1.
<ICNTWCSTA1>-FISCPER = 1.
ENDLOOP. LOOP AT IT_ICNTWCSTA1 INTO WA_ICNTWCSTA1. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_ICNTWCSTA1-PSPID, sy-vline,
WA_ICNTWCSTA1-POSID, sy-vline,
WA_ICNTWCSTA1-AUFNR, sy-vline,
WA_ICNTWCSTA1-VTYPE, sy-vline,
WA_ICNTWCSTA1-VTDETAIL, sy-vline,
WA_ICNTWCSTA1-VTSTAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ICNTWCSTA1 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_ICNTWCSTA1 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_ICNTWCSTA1 INTO WA_ICNTWCSTA1. *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 BELNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-BELNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-BELNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit PERI7, internal->external for field FISCPER CALL FUNCTION 'CONVERSION_EXIT_PERI7_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-FISCPER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-FISCPER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field PSPID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-PSPID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-PSPID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field POSID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-POSID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-POSID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AUFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-AUFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-AUFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VERSN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-VERSN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-VERSN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KSTAR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-KSTAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-KSTAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CCTR_IBV CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-CCTR_IBV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-CCTR_IBV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWG CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-SWG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-SWG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWF CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-SWF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-SWF.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWV CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-SWV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-SWV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-MEINH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-MEINH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SAKNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-SAKNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-SAKNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REFBN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-REFBN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-REFBN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field REFGJ CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_ICNTWCSTA1-REFGJ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICNTWCSTA1-REFGJ.
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_ICNTWCSTA1_STR,
KOKRS TYPE STRING,
BELNR TYPE STRING,
BUZEI TYPE STRING,
FISCVAR TYPE STRING,
FISCPER TYPE STRING,
PSPID TYPE STRING,
POSID TYPE STRING,
AUFNR TYPE STRING,
VTYPE TYPE STRING,
VTDETAIL TYPE STRING,
VTSTAT TYPE STRING,
MEASTYPE TYPE STRING,
VERSN TYPE STRING,
VALUTYP TYPE STRING,
CORRTYPE TYPE STRING,
KSTAR TYPE STRING,
SEKNZ TYPE STRING,
RSPOBART TYPE STRING,
RSPAROBVAL TYPE STRING,
CCTR_IBV TYPE STRING,
SWG TYPE STRING,
SWF TYPE STRING,
SWV TYPE STRING,
SME TYPE STRING,
SMA TYPE STRING,
SMEG TYPE STRING,
SMEF TYPE STRING,
SMEV TYPE STRING,
WAERS TYPE STRING,
CURTYPE TYPE STRING,
MEINH TYPE STRING,
BLDAT TYPE STRING,
BUDAT TYPE STRING,
SGTXT TYPE STRING,
RSAUXACCTYPE TYPE STRING,
RSAUXACCVAL TYPE STRING,
BUKRS TYPE STRING,
GSBER TYPE STRING,
FKBER TYPE STRING,
PBUKRS TYPE STRING,
PFKBER TYPE STRING,
WERKS TYPE STRING,
MATNR TYPE STRING,
PERNR TYPE STRING,
KTOPL TYPE STRING,
SAKNR TYPE STRING,
LIFNR TYPE STRING,
KUNNR TYPE STRING,
REFBT TYPE STRING,
REFBN TYPE STRING,
REFBK TYPE STRING,
REFGJ TYPE STRING,
REFBZ TYPE STRING,
DUMMY_INCL_EEW_COBL TYPE STRING,
GUID TYPE STRING,
CPR_GUID TYPE STRING,END OF T_EKKO_STR. DATA: WA_ICNTWCSTA1_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_ICNTWCSTA1_STR-KOKRS sy-vline
WA_ICNTWCSTA1_STR-BELNR sy-vline
WA_ICNTWCSTA1_STR-BUZEI sy-vline
WA_ICNTWCSTA1_STR-FISCVAR sy-vline
WA_ICNTWCSTA1_STR-FISCPER sy-vline
WA_ICNTWCSTA1_STR-PSPID sy-vline
WA_ICNTWCSTA1_STR-POSID sy-vline
WA_ICNTWCSTA1_STR-AUFNR sy-vline
WA_ICNTWCSTA1_STR-VTYPE sy-vline
WA_ICNTWCSTA1_STR-VTDETAIL sy-vline
WA_ICNTWCSTA1_STR-VTSTAT sy-vline
WA_ICNTWCSTA1_STR-MEASTYPE sy-vline
WA_ICNTWCSTA1_STR-VERSN sy-vline
WA_ICNTWCSTA1_STR-VALUTYP sy-vline
WA_ICNTWCSTA1_STR-CORRTYPE sy-vline
WA_ICNTWCSTA1_STR-KSTAR sy-vline
WA_ICNTWCSTA1_STR-SEKNZ sy-vline
WA_ICNTWCSTA1_STR-RSPOBART sy-vline
WA_ICNTWCSTA1_STR-RSPAROBVAL sy-vline
WA_ICNTWCSTA1_STR-CCTR_IBV sy-vline
WA_ICNTWCSTA1_STR-SWG sy-vline
WA_ICNTWCSTA1_STR-SWF sy-vline
WA_ICNTWCSTA1_STR-SWV sy-vline
WA_ICNTWCSTA1_STR-SME sy-vline
WA_ICNTWCSTA1_STR-SMA sy-vline
WA_ICNTWCSTA1_STR-SMEG sy-vline
WA_ICNTWCSTA1_STR-SMEF sy-vline
WA_ICNTWCSTA1_STR-SMEV sy-vline
WA_ICNTWCSTA1_STR-WAERS sy-vline
WA_ICNTWCSTA1_STR-CURTYPE sy-vline
WA_ICNTWCSTA1_STR-MEINH sy-vline
WA_ICNTWCSTA1_STR-BLDAT sy-vline
WA_ICNTWCSTA1_STR-BUDAT sy-vline
WA_ICNTWCSTA1_STR-SGTXT sy-vline
WA_ICNTWCSTA1_STR-RSAUXACCTYPE sy-vline
WA_ICNTWCSTA1_STR-RSAUXACCVAL sy-vline
WA_ICNTWCSTA1_STR-BUKRS sy-vline
WA_ICNTWCSTA1_STR-GSBER sy-vline
WA_ICNTWCSTA1_STR-FKBER sy-vline
WA_ICNTWCSTA1_STR-PBUKRS sy-vline
WA_ICNTWCSTA1_STR-PFKBER sy-vline
WA_ICNTWCSTA1_STR-WERKS sy-vline
WA_ICNTWCSTA1_STR-MATNR sy-vline
WA_ICNTWCSTA1_STR-PERNR sy-vline
WA_ICNTWCSTA1_STR-KTOPL sy-vline
WA_ICNTWCSTA1_STR-SAKNR sy-vline
WA_ICNTWCSTA1_STR-LIFNR sy-vline
WA_ICNTWCSTA1_STR-KUNNR sy-vline
WA_ICNTWCSTA1_STR-REFBT sy-vline
WA_ICNTWCSTA1_STR-REFBN sy-vline
WA_ICNTWCSTA1_STR-REFBK sy-vline
WA_ICNTWCSTA1_STR-REFGJ sy-vline
WA_ICNTWCSTA1_STR-REFBZ sy-vline
WA_ICNTWCSTA1_STR-DUMMY_INCL_EEW_COBL sy-vline
WA_ICNTWCSTA1_STR-GUID sy-vline
WA_ICNTWCSTA1_STR-CPR_GUID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.