How to split a field into 10 new fields using Substring command in sql - sql

I have a field that I title, nothing. As of yet it has no value. It is 261 characters at the end of my fixed width file, largefile. Now, I am being told to break this 261 character field into 10 separate fields. I can reimport it using this new schema. I found something else on this site I found something else on another site and it makes sense but it seems as if I am missing a few tidbits of code. Any thoughts on if I am going about this the right way?
I have tried the following code but ending in error.
update dbo.largefile
set blank1 = substring(nothing,1,9)
unkn1 = substring(nothing,10,1)
unkn2 = substring(nothing,11,1)
blank2 = substring(nothing,12,35)
unkn3 = substring(nothing,47,4)
unkn4 = substring(nothing,51,1)
contact = substring(nothing,52,35)
title = substring(nothing,87,35)
contactphone = substring(nothing,122,10)
website = substring(nothing,132,204)
unkn5 = substring(nothing,203,59);
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'unkn1'.

You are missing commas after each assignment:
update dbo.largefile
set blank1 = substring(nothing,1,9),
unkn1 = substring(nothing,10,1),
unkn2 = substring(nothing,11,1),
blank2 = substring(nothing,12,35),
unkn3 = substring(nothing,47,4),
unkn4 = substring(nothing,51,1),
contact = substring(nothing,52,35),
title = substring(nothing,87,35),
contactphone = substring(nothing,122,10),
website = substring(nothing,132,204),
unkn5 = substring(nothing,203,59);

Related

Error in if (all(x > 0)) { : missing value where TRUE/FALSE needed in glMDPlot

I am analyzing RNA sequencing data with 4 treatments. During the process in r, I got an error below with the code. It is to make a glimma MDplot. It would be appreciated that anyone solve this problem.
All treatments include 4 replicates, but one of them has only 3. I am unsure that this exerts the error, but just in case, I informed.
glMDPlot(fit.trend2, counts = logCPM.trend, status = trend_global_0.1, coef = 1, groups = d.filt$samples$group, samples = d.filt$samples$Label, sample.cols = d.filt$samples$col, folder = "glimma-plots", html = "HvsC_trend_globalFDR", main = "H. vs. C.", launch = TRUE)
Error in if (all(x > 0)) { : missing value where TRUE/FALSE needed

Update SD condition records using FM/BAPI

I am trying to update DATBI field of A* pricing condition tables using the data coming from excel file.I have tried below approaches but unable to update the entry as DATBI is key field. It creates new record instead of updating the existing one. Approaches:
FM: RV_CONDITION_COPY(with mai tain_ mode as B)
FM: RV_CONDITION_MAINTENANCE(using maintain_mode as B)
BAPI_PRICES_CONDITIONS(It changes KONH table but not A* table.Also, as per note#1135984,we shouldn't be using it)
FM:RV_KONDITION_SICHERN_V13A in update mode(This gives sy-subrc 4 in this FM post update A* from table__ syntax as the datbi is new coming from my excel file)
Idoc COND_A04(This also creates new entry instead of updating existing one)
BDC is the only approach that I can think of but looking at VK12 screen, it has been observed that based on key combination and its underlying A* tables, it should be dynamic.
Can you please help in this regard?Is there any dynamic BDC for VK12?
Undoubtedly we shouldn't use BAPI_PRICES_CONDITIONS, and note 94443 describes the problems it can cause when you push incorrect conditions into system, but sometime there is no way to avoid it. I tried this FM and it definitely worked on my system.
Here is the code for updating A009 table:
* header table
APPEND INITIAL LINE TO lt_head ASSIGNING <fs_head>.
<fs_head>-operation = '009'.
<fs_head>-cond_usage = 'A'.
<fs_head>-table_no = '007'.
<fs_head>-applicatio = 'V'.
<fs_head>-cond_type = 'ZP15'.
<fs_head>-valid_from = '20210103'.
<fs_head>-valid_to = '99991231'.
<fs_head>-cond_no = '$000000001'.
<fs_head>-varkey = 'BE110101001000635199993112'.
** items
APPEND INITIAL LINE TO lt_konh ASSIGNING <fs_konh>.
<fs_konh>-operation = '009'.
<fs_konh>-cond_no = '$000000001'.
<fs_konh>-cond_usage = 'A'.
<fs_konh>-table_no = '007'.
<fs_konh>-applicatio = 'V'.
<fs_konh>-cond_type = 'ZP15'.
<fs_konh>-valid_from = '20210103'.
<fs_konh>-valid_to = '99991231'.
<fs_konh>-created_by = sy-uname.
<fs_konh>-creat_date = sy-datum.
APPEND INITIAL LINE TO lt_konp ASSIGNING <fs_konp>.
<fs_konp>-operation = '009'.
<fs_konp>-cond_no = '$000000001'.
<fs_konp>-cond_count = '01'.
<fs_konp>-applicatio = 'V'.
<fs_konp>-cond_type = 'ZP15'.
<fs_konp>-scaletype = 'A'.
<fs_konp>-scalebasin = space.
<fs_konp>-scale_qty = '0'.
<fs_konp>-cond_p_unt = '1'.
<fs_konp>-cond_unit = 'ΠΆ'.
<fs_konp>-calctypcon = 'C'.
<fs_konp>-cond_value = '160'.
<fs_konp>-condcurr = 'EUR'.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
pi_initialmode = abap_true
TABLES
ti_bapicondct = lt_head
ti_bapicondhd = lt_konh
ti_bapicondit = lt_konp
ti_bapicondqs = lt_konm
ti_bapicondvs = lt_konw
to_bapiret2 = lt_return
to_bapiknumhs = lt_knumh
to_mem_initial = lt_buffer
EXCEPTIONS
update_error = 1
OTHERS = 2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = abap_true.
I tried the above code and record with the specified key was properly updated with new valid to field (DATAB). Updating DATBI is a bit more complicated since it is included in the primary key and cannot be updated in one step. You must delete the record with the old DATBI and the create the new one. In this blog you can read more about how to use this BAPI:
https://blogs.sap.com/2019/07/22/how-to-use-bapi_prices_conditions-to-mass-upload-price-conditions/

How do I create a service ticket using CRM_ORDER_MAINTAIN?

I'm trying to learn the Function Module CRM_ORDER_MAINTAIN and so far I managed to create a standard order with partners and their roles, however now I'm having trouble creating a service ticket with its required fields.
I tried debugging the FM when calling it from WEBUI to see what structures and tables are to be filled but I'm having a bit of trouble figuring out which ones to fill and which ones are generated and don't know if I'm missing something small somewhere that's causing it not to save.
I think the error lies in this part of the code that handles Categorization, because the other code that handles adding partners worked for the standard order.
I'm not filling any GUIDS and only filling HANDLES because that's what I did for the standard order.
*****categorization: motive+submotive******
clear ls_input_fields.
clear ls_fieldsname.
ls_fieldsname-fieldname = 'CONC_KEY'.
INSERT ls_fieldsname INTO TABLE ls_input_fields-field_names.
ls_input_fields-ref_handle = 1."
ls_input_fields-ref_kind = gc_object_kind-orderadm_h.
ls_input_fields-objectname = 'SERVICE_OS'.
ls_subject-ref_handle = ls_orderadm_h-handle.
ls_subject-ref_handle_h = ls_orderadm_h-handle.
ls_subject-katalogart = 'Z1'.
ls_subject-codegruppe = 'ZCA00001'.
ls_subject-code = 'Z044'.
append ls_subject TO ls_osset-subject.
ls_osset-ref_handle = ls_orderadm_h-handle.
ls_osset-profile_type = 'A'.
ls_osset-subject_profile = 'ZCCCAST'.
append ls_osset to ls_service_os-osset.
ls_service_os-ref_handle = ls_orderadm_h-handle.
append ls_service_os to it_service_os.
INSERT ls_input_fields INTO TABLE lt_input_fields.
ls_subject-ref_handle = ls_orderadm_h-handle.
ls_subject-ref_handle_h = ls_orderadm_h-handle.
ls_subject-katalogart = 'Z1'.
ls_subject-codegruppe = 'ZCA00002'.
ls_subject-code = 'Z009'.
append ls_subject TO ls_osset-subject.
ls_osset-ref_handle = ls_orderadm_h-handle.
ls_osset-profile_type = 'A'.
ls_osset-subject_profile = 'ZCCCAST'.
append ls_osset to ls_service_os-osset.
ls_service_os-ref_handle = ls_orderadm_h-handle.
append ls_service_os to it_service_os.
INSERT ls_input_fields INTO TABLE lt_input_fields.
Any help is appreciated
For Service OS there is a multilevel categorization up to four levels. You can check the hierarchy via CRM_ORDER_READ FM in parameter ET_SERVICE_OS.
Also, you can check the hierarchy in the below structure CRMT_SRV_OSSET_WRK
To maintain the data for more than 2 levels of hierarchy you have to create a new ref GUID. You have to prepare and fill data to Create OS as below
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = lv_ref_guid.
ls_subject-ref_handle = '0000000000'.
ls_subject-ref_guid = lv_ref_guid. " newly created ref GUID
ls_subject-cat_id = 'As per your req.'.
ls_subject-katalog_type = ''.
ls_subject-mode = 'A'. "For creation A, for update B
" maintain other Subject parameter as per your requirement
APPEND ls_subject TO lt_subject.
" you can skip preparing Ref-Object structure if you don't want to update
ls_refobj-ref_guid = lv_ref_guid. " newly created ref GUID
ls_refobj-product_id = "Product ID". " optional
ls_refobj-ref_handle = '0000000000'.
ls_refobj-main_object = abap_true.
ls_refobj-mode = 'A'. " mode A for creating, B for update
INSERT ls_refobj INTO TABLE lt_refobj.
ls_osset-ref_handle = '0000000000'.
ls_osset-ref_guid = "Header or Item GUID of Service".
ls_osset-subject_profile = 'SERVICE'.
ls_osset-profile_type = 'A'. " service profile type
ls_osset-refobject = lt_refobj.
ls_osset-subject = lt_subject.
INSERT ls_osset INTO TABLE lt_osset.
ls_service_os-ref_guid = "Header or Item GUID of Service".
ls_service_os-ref_kind = "A or B". " A for Header and B for Item
ls_service_os-osset = lt_osset.
INSERT ls_service_os INTO TABLE lt_service_os.

I am trying to set a series name dynamicallly in amcharts

I passing data into a line series but I cannot dynamically add anything to series.name I just get the string rather that teh variable.
I tried using .dataFields.name but this is teh incorrect syntax.
Please advise?
J
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "value"+ seriesId;
series.dataFields.dateX = "date";
series.name = "BrandNM"+ seriesId;
series.strokeWidth = 2;

Add business objects to contacts

I've successfully created a contact in the SAP IS-U (Release 618) system using the function: BCONTACT_CREATE
EDIT:
Since this question was voted "close" for being "too broad" - here's some very specific code:
DATA:
ls_contact TYPE bpc01_bcontact_auto,
ls_contact_properties TYPE bcont,
lv_contact_text TYPE string,
lv_bp TYPE bu_partner,
lv_bpcontact_id TYPE ct_contact,
lv_no_dialog TYPE flag VALUE abap_true,
lv_repid TYPE syst-repid.
* Main logic
lv_contact_text = 'Test'.
lv_bp = '0010000062'.
ls_contact_properties-cclass = '0003'.
ls_contact_properties-activity = '0001'.
ls_contact_properties-f_coming = '3'.
* Mapping
*--------------------------------------------------------------------*
ls_contact-notice-line = lv_contact_text.
ls_contact-bcontd = ls_contact_properties.
* set flag to use auto data
ls_contact-bcontd_use = abap_true.
lv_repid = sy-repid.
CALL FUNCTION 'BCONTACT_CREATE'
EXPORTING
x_no_dialog = lv_no_dialog
x_auto = ls_contact
x_prgcontext = lv_repid
x_partner = lv_bp
IMPORTING
y_new_bpcontact = lv_bpcontact_id
EXCEPTIONS
existing = 1
foreign_lock = 2
number_error = 3
general_fault = 4
input_error = 5
not_authorized = 6
OTHERS = 7.
When I open the created contact in the BCT2 transaction I see the nothing under Business-Objects:
How can I programmatically add a business object to a contact, so that it is displayed here like this?
I found it a solution!
First create variables (a table and a structure for filling the table) for your business objects that you want to add (I saw some code that had a limit of 5 so I just set that too to be safe):
lt_business_objs TYPE TABLE OF bpc_obj INITIAL SIZE 5,
ls_business_obj TYPE bpc_obj,
Next append your object, in this example I'm just appending one:
* Append business objects
*--------------------------------------------------------------------*
ls_business_obj-objkey = 'The value here may be your business object input value'.
ls_business_obj-objrole = 'DEFAULT'. "Don't know what this is for...
ls_business_obj-objtype = 'OBJECT_NAME'. "Name of your business object - seen in table TOJTB
APPEND ls_business_obj TO lt_business_objs.
And lastly put the object list into the contact structure:
ls_contact-iobjects = lt_business_objs.