ABAP Select data from SAP table VTCORT_CODULCO 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 VTCORT_CODULCO 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 VTCORT_CODULCO. 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 VTCORT_CODULCO 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_VTCORT_CODULCO TYPE STANDARD TABLE OF VTCORT_CODULCO, WA_VTCORT_CODULCO TYPE VTCORT_CODULCO, 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: <VTCORT_CODULCO> TYPE VTCORT_CODULCO. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VTCORT_CODULCO. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VTCORT_CODULCO INTO TABLE IT_VTCORT_CODULCO. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VTCORT_CODULCO * INTO TABLE @DATA(IT_VTCORT_CODULCO2). *--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_VTCORT_CODULCO INDEX 1 INTO DATA(WA_VTCORT_CODULCO2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VTCORT_CODULCO ASSIGNING <VTCORT_CODULCO>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VTCORT_CODULCO>-MANDT = 1.
<VTCORT_CODULCO>-CODULCO_UUID = 1.
<VTCORT_CODULCO>-CODMD_UUID = 1.
<VTCORT_CODULCO>-CODUL_UUID = 1.
<VTCORT_CODULCO>-COMPANYCODE = 1.
ENDLOOP. LOOP AT IT_VTCORT_CODULCO INTO WA_VTCORT_CODULCO. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VTCORT_CODULCO-DEAL_NUMBER, sy-vline,
WA_VTCORT_CODULCO-UL_NUMBER, sy-vline,
WA_VTCORT_CODULCO-COND_NUMBER, sy-vline,
WA_VTCORT_CODULCO-TYPE, sy-vline,
WA_VTCORT_CODULCO-CLASS, sy-vline,
WA_VTCORT_CODULCO-CATEGORY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VTCORT_CODULCO 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_VTCORT_CODULCO 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_VTCORT_CODULCO INTO WA_VTCORT_CODULCO. *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 DEAL_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VTCORT_CODULCO-DEAL_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VTCORT_CODULCO-DEAL_NUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field UL_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VTCORT_CODULCO-UL_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VTCORT_CODULCO-UL_NUMBER.
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_VTCORT_CODULCO_STR,
MANDT TYPE STRING,
CODULCO_UUID TYPE STRING,
CODMD_UUID TYPE STRING,
CODUL_UUID TYPE STRING,
COMPANYCODE TYPE STRING,
DEAL_NUMBER TYPE STRING,
UL_NUMBER TYPE STRING,
COND_NUMBER TYPE STRING,
TYPE TYPE STRING,
CLASS TYPE STRING,
CATEGORY TYPE STRING,
EFF_FROM TYPE STRING,
EFF_FROM_EXCL TYPE STRING,
DIRECTION TYPE STRING,
CREATE_USER TYPE STRING,
CREATE_DATE TYPE STRING,
CREATE_TIME TYPE STRING,
UPDATE_USER TYPE STRING,
UPDATE_DATE TYPE STRING,
UPDATE_TIME TYPE STRING,
ZERO_CONDITION TYPE STRING,
FIX_PERC_RATE TYPE STRING,
FIX_PAYMENT_RATE TYPE STRING,
FIX_BASIS TYPE STRING,
VAR_INT_REF TYPE STRING,
VAR_SPREAD TYPE STRING,
VAR_FORMULA TYPE STRING,
VAR_FORMULA_NAME TYPE STRING,
VAR_1ST_PER_RATE TYPE STRING,
CALC_METHOD TYPE STRING,
CALC_METHOD_CAL TYPE STRING,
CALC_TYPE TYPE STRING,
CALC_EXP_FREQ TYPE STRING,
CALC_IMM_SETTLE TYPE STRING,
AMOUNT TYPE STRING,
AMOUNT_CURRENCY TYPE STRING,
AMOUNT_TEMP_CALC TYPE STRING,
CALCDAT TYPE STRING,
CALCDAT_INCL TYPE STRING,
CALCDAT_MONTHEND TYPE STRING,
CALCDAT_WKDAYSFT TYPE STRING,
CALCDAT_SFTDAYS TYPE STRING,
CALCDAT_SFTDIR TYPE STRING,
CALCDAT_PERRULE TYPE STRING,
CALCDAT_ADJRULE TYPE STRING,
DUEDAT TYPE STRING,
DUEDAT_MONTHEND TYPE STRING,
DUEDAT_SFTEND TYPE STRING,
DUEDAT_WKDAYSFT TYPE STRING,
DUEDAT_SFTDAYS TYPE STRING,
DUEDAT_SFTDIR TYPE STRING,
DUEDAT_DUERULE TYPE STRING,
DUEDAT_FIXRULE TYPE STRING,
DUEDAT_FIXREFDAT TYPE STRING,
FREQUENCY TYPE STRING,
FREQUENCY_UNIT TYPE STRING,
CALENDAR1 TYPE STRING,
CALENDAR2 TYPE STRING,
CALENDAR3 TYPE STRING,
ROUND TYPE STRING,
ROUND_UNIT TYPE STRING,
SINGLE_DATES TYPE STRING,
DISCOUNT TYPE STRING,
VARNAME TYPE STRING,
ALT_INT_RATE TYPE STRING,
ALT_INT_REF TYPE STRING,
KZ TYPE STRING,END OF T_EKKO_STR. DATA: WA_VTCORT_CODULCO_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_VTCORT_CODULCO_STR-MANDT sy-vline
WA_VTCORT_CODULCO_STR-CODULCO_UUID sy-vline
WA_VTCORT_CODULCO_STR-CODMD_UUID sy-vline
WA_VTCORT_CODULCO_STR-CODUL_UUID sy-vline
WA_VTCORT_CODULCO_STR-COMPANYCODE sy-vline
WA_VTCORT_CODULCO_STR-DEAL_NUMBER sy-vline
WA_VTCORT_CODULCO_STR-UL_NUMBER sy-vline
WA_VTCORT_CODULCO_STR-COND_NUMBER sy-vline
WA_VTCORT_CODULCO_STR-TYPE sy-vline
WA_VTCORT_CODULCO_STR-CLASS sy-vline
WA_VTCORT_CODULCO_STR-CATEGORY sy-vline
WA_VTCORT_CODULCO_STR-EFF_FROM sy-vline
WA_VTCORT_CODULCO_STR-EFF_FROM_EXCL sy-vline
WA_VTCORT_CODULCO_STR-DIRECTION sy-vline
WA_VTCORT_CODULCO_STR-CREATE_USER sy-vline
WA_VTCORT_CODULCO_STR-CREATE_DATE sy-vline
WA_VTCORT_CODULCO_STR-CREATE_TIME sy-vline
WA_VTCORT_CODULCO_STR-UPDATE_USER sy-vline
WA_VTCORT_CODULCO_STR-UPDATE_DATE sy-vline
WA_VTCORT_CODULCO_STR-UPDATE_TIME sy-vline
WA_VTCORT_CODULCO_STR-ZERO_CONDITION sy-vline
WA_VTCORT_CODULCO_STR-FIX_PERC_RATE sy-vline
WA_VTCORT_CODULCO_STR-FIX_PAYMENT_RATE sy-vline
WA_VTCORT_CODULCO_STR-FIX_BASIS sy-vline
WA_VTCORT_CODULCO_STR-VAR_INT_REF sy-vline
WA_VTCORT_CODULCO_STR-VAR_SPREAD sy-vline
WA_VTCORT_CODULCO_STR-VAR_FORMULA sy-vline
WA_VTCORT_CODULCO_STR-VAR_FORMULA_NAME sy-vline
WA_VTCORT_CODULCO_STR-VAR_1ST_PER_RATE sy-vline
WA_VTCORT_CODULCO_STR-CALC_METHOD sy-vline
WA_VTCORT_CODULCO_STR-CALC_METHOD_CAL sy-vline
WA_VTCORT_CODULCO_STR-CALC_TYPE sy-vline
WA_VTCORT_CODULCO_STR-CALC_EXP_FREQ sy-vline
WA_VTCORT_CODULCO_STR-CALC_IMM_SETTLE sy-vline
WA_VTCORT_CODULCO_STR-AMOUNT sy-vline
WA_VTCORT_CODULCO_STR-AMOUNT_CURRENCY sy-vline
WA_VTCORT_CODULCO_STR-AMOUNT_TEMP_CALC sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_INCL sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_MONTHEND sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_WKDAYSFT sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_SFTDAYS sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_SFTDIR sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_PERRULE sy-vline
WA_VTCORT_CODULCO_STR-CALCDAT_ADJRULE sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_MONTHEND sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_SFTEND sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_WKDAYSFT sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_SFTDAYS sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_SFTDIR sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_DUERULE sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_FIXRULE sy-vline
WA_VTCORT_CODULCO_STR-DUEDAT_FIXREFDAT sy-vline
WA_VTCORT_CODULCO_STR-FREQUENCY sy-vline
WA_VTCORT_CODULCO_STR-FREQUENCY_UNIT sy-vline
WA_VTCORT_CODULCO_STR-CALENDAR1 sy-vline
WA_VTCORT_CODULCO_STR-CALENDAR2 sy-vline
WA_VTCORT_CODULCO_STR-CALENDAR3 sy-vline
WA_VTCORT_CODULCO_STR-ROUND sy-vline
WA_VTCORT_CODULCO_STR-ROUND_UNIT sy-vline
WA_VTCORT_CODULCO_STR-SINGLE_DATES sy-vline
WA_VTCORT_CODULCO_STR-DISCOUNT sy-vline
WA_VTCORT_CODULCO_STR-VARNAME sy-vline
WA_VTCORT_CODULCO_STR-ALT_INT_RATE sy-vline
WA_VTCORT_CODULCO_STR-ALT_INT_REF sy-vline
WA_VTCORT_CODULCO_STR-KZ sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.